package com.lyfx.ly.service.impl;

import com.lyfx.ly.vo.AttrGroupRelationVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyfx.common.utils.PageUtils;
import com.lyfx.common.utils.Query;

import com.lyfx.ly.dao.AttrAttrgroupDao;
import com.lyfx.ly.entity.AttrAttrgroupEntity;
import com.lyfx.ly.service.AttrAttrgroupService;


@Service("attrAttrgroupService")
public class AttrAttrgroupServiceImpl extends ServiceImpl<AttrAttrgroupDao, AttrAttrgroupEntity> implements AttrAttrgroupService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AttrAttrgroupEntity> page = this.page(
                new Query<AttrAttrgroupEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveBatch(List<AttrGroupRelationVo> vos) {
        List<AttrAttrgroupEntity> collect = vos.stream().map(item -> {
            AttrAttrgroupEntity attrgroupEntity = new AttrAttrgroupEntity();
            BeanUtils.copyProperties(item, attrgroupEntity);
            return attrgroupEntity;
        }).collect(Collectors.toList());
        this.saveBatch(collect);
    }

}